﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataBaseHelper
{
    class Program
    {
        
        
        private class DB
        {
            private string _server;
            public string Server
            {
                get { return _server; }
                set { _server = value; }
            }
            private string _port;
            public string Port
            {
                get { return _port; }
                set { _port = value; }
            }
            private string _userId;
            public string UserId
            {
                get { return _userId; }
                set { _userId = value; }
            }
            private string _password;
            public string Password
            {
                get { return _password; }
                set { _password = value; }
            }
            private string _database;
            public string Database
            {
                get { return _database; }
                set { _database = value; }
            }

            private string _baseTable;
            public string BaseTable
            {
                get { return _baseTable; }
                set { _baseTable = value; }
            }

            public DB() { }
            public void setDataBase()
            {
                Console.WriteLine("Proszę podać server bazy danych: ");
                Server = Console.ReadLine();
                Console.WriteLine("");
                Console.WriteLine("Port: ");
                Port = Console.ReadLine();
                Console.WriteLine("");
                Console.WriteLine("Nazwa użytkownika: ");
                UserId = Console.ReadLine();
                Console.WriteLine("");
                Console.WriteLine("Hasło: ");
                Password = Console.ReadLine();
                Console.WriteLine("");
                Console.WriteLine("Nazwa bazy danych: ");
                Database = Console.ReadLine();
                Console.WriteLine("");
                Console.WriteLine("Nazwa tabeli z danymi: ");
                BaseTable = Console.ReadLine();
            }
        }

        static void Main(string[] args)
        {
            Dictionary<string, string> companies = new Dictionary<string, string>();
            companies.Add("agora", "01PLAGORA00067");
            companies.Add("assecopol", "01PLSOFTB00016");
            companies.Add("bioton", "01PLBIOTN00029");
            companies.Add("bre", "01PLBRE0000012");
            companies.Add("bzwbk", "01PLBZ00000044");
            companies.Add("cersanit", "01PLCRSNT00011");
            companies.Add("cez", "01CZ0005112300");
            companies.Add("cyfrplsat", "01PLCFRPT00013");
            companies.Add("getin", "01PLGSPR000014");
            companies.Add("gtc", "01PLGTC0000037");
            companies.Add("kghm", "01PLKGHM000017");
            companies.Add("lotos", "01PLLOTOS00025");
            companies.Add("pbg", "01PLPBG0000029");
            companies.Add("pekao", "01PLPEKAO00016");
            companies.Add("pgnig", "01PLPGNIG00014");
            companies.Add("pknorlen", "01PLPKN0000018");
            companies.Add("pkobp", "01PLPKO0000016");
            companies.Add("polimexms", "01PLMSTSD00019");
            companies.Add("tpsa", "01PLTLKPL00017");
            companies.Add("tvn", "01PLTVN0000017");
            
            Console.WriteLine("*************************************************");
            Console.WriteLine("DataBaseHelper v1.0");
            Console.WriteLine("Author: Mariusz Sokołowski");
            Console.WriteLine("Program służący do kreawania potrzebnych widoków z tabeli 'notawania' dla podanej spółki");
            Console.WriteLine("*************************************************");
            Console.WriteLine("");

            DB db = new DB();

            while (true)
            {
                writeOptionToChoose();
                string input = Console.ReadLine();
                switch (input)
                {
                    case "0":
                        return;
                    case "1":
                        db.setDataBase();
                        break;
                    case "2":
                        createViews(db, companies);
                        break;
                    default:
                        Console.WriteLine("Nie ma takiej opcji!");
                        break;
                }
            }

        }

        static void writeOptionToChoose()
        {
            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("Proszę wybrać komende:");
            Console.WriteLine("0. Wyjście");
            Console.WriteLine("1. Ustaw baze danych.");
            Console.WriteLine("2. Kreuj widoki.");
            Console.WriteLine("");
        }

        private static void createViews(DB db, Dictionary<string, string> com)
        {
            Console.WriteLine("");
            DataBase bazaDanych = new DataBase(db.Server, db.Port, db.UserId, db.Password, db.Database, db.BaseTable);
            foreach (KeyValuePair<string, string> pair in com)
            {
                Console.WriteLine("Creating views for " + pair.Key + " (" + pair.Value + ")");
                bazaDanych.createCompanyView(pair.Key, pair.Value);
                bazaDanych.createComValue(pair.Key, pair.Value);
                bazaDanych.createComSalesView(pair.Key, pair.Value);
                bazaDanych.createComPurchaseView(pair.Key, pair.Value);
            }
            Console.WriteLine("");
        }

        
    }
}
